﻿using System.Linq;
using XRM.Security.DataAccess.Models;

namespace XRM.Security.DataAccess.Repositories.Impl
{
    public class RoleMemberRepository : BaseRepository<RoleMember>
    {
        public bool UserInRole(int userId, string role)
        {
            return ContextDb.RoleMembers.Any( s => s.Role.Name == role && s.UserId == userId );
        }

        public IQueryable<Role> GetRolesByUserId(int userId)
        {
            return ContextDb.RoleMembers.Where( s => s.UserId == userId ).Select( s => s.Role );
        }

        public IQueryable<Role> GetAllRoles()
        {
            return ContextDb.Roles;
        }
    }
}
